#include <string>
#include <opencv2/opencv.hpp>

#include "palmdll_yjy.h"

using namespace std;

extern "C"
{
/*
parameters:
@palmprint: w*h,CV_8UC3
@roi: 128*128,CV_8U
*/
void extractROI(unsigned char *palmprint, unsigned char *roi) {
//    if (NULL == palmprint)
//        printf("true!");
//    else
//        printf("false!");
//    for (int i = 0; i < 640; ++i) {
//        for (int j = 0; j < 480; ++j) {
//            printf("%d", 1 + palmprint[i * 480 + j]);
//        }
//    }
//    printf("%s", palmprint);
    const int roi_size = 128;
//    unsigned char *palmprint_data = new unsigned char[640 * 480];
//    memcpy(palmprint_data, palmprint, 640 * 480);
    IplImage *p = cvCreateImage(cvSize(640, 480), IPL_DEPTH_8U, 1);
    p->imageData = (char *) palmprint;

    IplImage *roi_img = getROI(p, false, "");

    if (NULL == roi_img)
        return;
    memcpy(roi, roi_img->imageData, roi_size * roi_size);
    cvReleaseImage(&roi_img);
}
}
